<template>
  <div class="data-table">
    <div class="title">{{title}}</div>
    <div class="table">
      <template v-for="(item, index) in data">
        <a-row :key="item.name" class="row" :class="{first: index === 0}">
          <a-col :span="3">
            <div class="title">{{item.name}}</div>
          </a-col>
          <a-col :span="7">
            <div class="box">
              <Unit
                :value="item.ytdTarget"
                mini
                label="target"
                :top="index === 0"
                :status="getStatus(item.ytdTarget, item.ytdActual)" />
              <div class="line" v-if="index === 0"></div>
              <Unit
                :value="item.ytdActual"
                mini
                label="actual"
                :top="index === 0"
                :status="getStatus(item.ytdTarget, item.ytdActual)" />
            </div>
          </a-col>
          <a-col :span="7">
            <div class="box">
              <Unit
                :value="item.currentTarget"
                mini
                label="target"
                :top="index === 0"
                :status="getStatus(item.currentTarget, item.currentActual)" />
              <div class="line" v-if="index === 0"></div>
              <Unit
                :value="item.currentActual"
                mini
                label="actual"
                :top="index === 0"
                :status="getStatus(item.currentTarget, item.currentActual)" />
            </div>
          </a-col>
          <a-col :span="7">
            <div class="box">
              <Unit
                :value="item.yeTarget"
                mini
                label="target"
                :top="index === 0"
                :status="getStatus(item.yeTarget, item.yeFc)" />
              <div class="line" v-if="index === 0"></div>
              <Unit
                :value="item.yeFc"
                mini
                label="fc"
                :top="index === 0"
                :status="getStatus(item.yeTarget, item.yeFc)" />
            </div>
          </a-col>
        </a-row>
      </template>
    </div>
  </div>
</template>

<script>
import Unit from '@/components/Unit.vue'
export default {
  components: {
    Unit
  },
  props: {
    title: String,
    data: Array
  },
  methods: {
    getStatus (a, b) {
      if (a === b) return ''
      if (a > b) {
        return 'up'
      } else {
        return 'down'
      }
    }
  }
}
</script>

<style scoped lang="scss">
.title {
  font-size: 14px;
  font-weight: 400;
  line-height: 40px;
}
.row {
  background-color: #F8F9F9;
  margin-bottom: 8px;

  .title {
    font-size: 14px;
    color: #5F93F3;
    font-weight: 400;
    line-height: 40px;
    margin-left: 16px;
  }
  .box {
    display: flex;
    margin: 0 auto;
    height: 40px;
    align-items: center;
    justify-content: space-between;
    max-width: 120px;
  }

  &.first {
    background-color: #fff;
    padding: 16px 0;
  }
  .line {
    width: 0;
    height: 20px;
    border-left: 1px solid #ccc;
  }
}
</style>
